package com.xiaohudie.JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author xiao hu die
 * @Date 2022/3/13 14:46
 * @Version 1.0
 */
public class TestDbUtils {
    public static void main(String[] args) throws SQLException {
        Connection connection =null;
        PreparedStatement preparedStatement =null;
        ResultSet resultSet =null;
        /**获取连接*/
         try {
             connection = DbUtils.getConnection();
             String SelectSql = "SELECT name FROM user where id =?";
             preparedStatement = connection.prepareStatement(SelectSql);
             preparedStatement.setInt(1, 7);
             resultSet = preparedStatement.executeQuery();
             while (resultSet.next()) {
                 String name = resultSet.getString("name");
                 System.out.println(name);
             }
         }finally {
             DbUtils.close(connection,preparedStatement,resultSet);
    }}
}
